package com.clsz.controller;

import com.clsz.bean.bo.FilmSearchBo;
import com.clsz.bean.po.Comment;
import com.clsz.bean.po.FilmInfo;
import com.clsz.service.FilmRegionService;
import com.clsz.service.CategoryService;
import com.clsz.service.FilmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/film")
public class FilmController {

    @Autowired
    private CategoryService categoryService;
    @Autowired
    private FilmRegionService filmRegionService;
    @Autowired
    private FilmService filmService;
    /***
     *电影类别 拍摄地 关键字搜索的电影
     * @return
     */
    @PostMapping
    public Object getCategoryList(FilmSearchBo filmSearchBo) {
        System.out.println("---------------------------->"+filmSearchBo.getPage());
        Map<String, Object> res = new HashMap<>();
        res.put("code", "200");
        res.put("message", "OK");
        Map<String, Object> data = new HashMap<>();
        data.put("categoryList", categoryService.getCategory());
        data.put("regionList", filmRegionService.getFilmRegionList());
        data.put("filmList", filmService.searchList(filmSearchBo));
        data.put("filmSearchBo", filmSearchBo);
        res.put("data", data);
        return res;
    }

    /**
     *查询影片详情
     * @return
     */

    @GetMapping("/{id}")
    public Object getOne(@PathVariable("id") Integer filmId) {
        System.out.println("============================"+filmId);
        Map<String, Object> res = new HashMap<>();
        Map<String, Object> data = new HashMap<>();
        FilmInfo filmInfo = filmService.searchOne(filmId);
        List<Comment> comment = filmService.getComment(filmId);
        if (filmInfo != null) {
            data.put("film", filmInfo);
            data.put("comment", comment);
            res.put("code", "200");
            res.put("message", "ok");
            res.put("data",data);
        } else {
            res.put("code", "500");
            res.put("message", "资源不存在");
            res.put("data",null);
        }
        return res;
    }
}
